package com.service.impl;

import com.bean.entity.Professional;
import com.bean.pojo.PageAssistant;
import com.dao.ProfessionalMapper;
import com.service.ProfessionalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * User: 刘文雄
 * Date:2022/3/30 15:00
 * 职称表基础业务逻辑
 */
@Service
public class ProfessionalServiceImpl implements ProfessionalService {
    @Autowired
    private ProfessionalMapper professionalMapper;
    @Override
    public int save(Professional t) throws Exception {
        int insert = professionalMapper.insert(t);
        if (insert==1)return 1;
        throw new Exception("新增职称失败");
    }
    @Override
    public int remove(Professional t) throws Exception {
        int delete = professionalMapper.delete(t);
        if (delete==1)return 1;
        throw new Exception("删除职称失败");
    }
    @Override
    public int modify(Professional t) throws Exception {
        int update = professionalMapper.update(t);
        if (update==1) return 1;
        throw new Exception("修改职称失败");
    }
    @Override
    public Professional unique(Professional t) throws Exception {
        List<Professional> professionalList = professionalMapper.select(t);
        if (professionalList.size() !=1) throw new Exception("无此职称");
        return professionalList.get(0);
    }
    @Override
    public List<Professional> query(Professional t) {
        List<Professional> professionalList = professionalMapper.select(t);
        return professionalList;

    }
    @Override
    public PageAssistant<Professional> queryByPage(Map<String, Object> map, PageAssistant<Professional> pa) {

        // 查询并设置记录总数
        pa.setCount(professionalMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());
        //查询并设置页面内容
        pa.setItems(professionalMapper.selectByPage(map));
        return pa;
    }
}
